// 通过blob数据下载文件   （将blob转为url下载）
export function downloadFileByBlob(res, filename = res.config.params.name) {
    const { data, headers } = res
    const blob = new Blob([data], { type: headers['content-type'] || data.type })
    let url = window.URL.createObjectURL(blob)
    downloadFileByUrl(url, filename)
}

// 通过url下载文件
export function downloadFileByUrl(url, filename) {
    let dom = document.createElement('a')
    dom.href = url
    filename && (dom.download = decodeURI(filename))
    dom.style.display = 'none'
    document.body.appendChild(dom)
    dom.click()
    dom.parentNode?.removeChild(dom)
    window.URL.revokeObjectURL(url)
}
